package com.ddstation.doctor_verify.service;

import java.util.List;

import javax.inject.Inject;

import com.ddstation.common.property.SystemProperties;
import com.ddstation.common.util.AliCloudOssUtil;
import com.ddstation.common.util.CheckUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.ddstation.common.model.ImageModel;
import com.ddstation.common.service.ImageService;
import com.ddstation.doctor.entity.DdDoctorEntity;
import com.ddstation.doctor.mapper.DdDoctorMapper;
import com.ddstation.doctor_verify.mapper.DoctorVerifyMapper;
import com.ddstation.doctor_verify.model.DoctorInfoModel;

@Service
public class DoctorVerifyServiceImpl implements DoctorVerifyService {
	
	@Override
	@Transactional(readOnly=true)
	public List<DoctorInfoModel> searchDoctorList(String institutionId,String doctorName){
		if("yes".equals(SystemProperties.IS_INNER_DATA)){
			return doctorVerifyMapper.selectDoctorsIsInner(institutionId,doctorName);//内网查询
		}else{
			return doctorVerifyMapper.selectDoctors(institutionId,doctorName);//外网查询
		}
	}
	
	// 查询单个医生审核信息
	@Override
	@Transactional(readOnly=true)
	public DdDoctorEntity searchDoctorVerifyInfo(int doctorId){
		return doctorVerifyMapper.selectByDoctorId(doctorId, "");
	}
	
	// 显示照片
	public List<ImageModel> searchImage(
			Integer isTest,
			Integer doctorId,
			String institutionId,
			String type){
		if (null == institutionId) {
			institutionId = "";
		} else if (!institutionId.startsWith("330185")) {
			institutionId = "";
		}
		DdDoctorEntity doctor = doctorVerifyMapper.selectByDoctorId(doctorId, institutionId);
		if(CheckUtil.isEmpty(doctor)){
			return null;
		}

		// 根据type显示不同的图片
		String attaStr = "";
		if ( "id_card".equals(type)){
			attaStr = doctor.getIdCardAtta();
			// 演示的卫监机构，不显示真实的身份证图片
			if (isTest.intValue() == 1) {
				attaStr = "84601,84602";
			}
		} else if ("qualification".equals(type)){
			attaStr = doctor.getQualificationAtta();
		} else if ("doctor_licence".equals(type)){
			attaStr = doctor.getDoctorLicenceAtta();
		}
		return imageService.fetchImage(attaStr);
	}//查看文件的类型
	
	@Override
	@Transactional(rollbackFor=Exception.class)
	public int update(DdDoctorEntity a){
		return ddDoctorMapper.update(a);
	}
	
	@Inject private DoctorVerifyMapper doctorVerifyMapper;
	@Inject private DdDoctorMapper ddDoctorMapper;
	@Inject private ImageService imageService;
}
